
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    flag: 0,
    houseList: null,
    follows: null,
    follow_count: 0,
    zaixian: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.scene == undefined) {
      var flag = 1;
      this.setData({flag:1})
      var user_id = options.user_id
    } else {
      var flag = 0;
      var user_id = decodeURIComponent(options.scene);
    }

    this.setData({
      user_id: user_id
    })

    this.setData({user_id: user_id})
    app.core('get', 'getAllProjectByUserId', { user_id: user_id, flag: flag}, (res) => {
      this.setData({
        houseList: res.data,
        code: res.user.ai_code,
        user: res.user,
        adviserInfo: res.adviserInfo
      })
    })

    this.followAndList()
    this.zaixian()
  },

  followAndList: function() {
    var open_id = wx.getStorageSync('user_new');
    var user_id = this.data.user_id;
    app.core('get', 'user/followAndList', { open_id: open_id, follow_user_id: user_id}, (res) => {
      this.setData({
        follows: res.data.follows,
        follow_count: res.data.count,
      })
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  bindAdviserChat: function (e) {
    let opid = wx.getStorageSync('user_new');
    let id = e.currentTarget.dataset.id;
    let that = this
    if (!opid){
      wx.showModal({
        title: '提示',
        content: '授权后可以查看楼盘信息，方便本平台提供更多优质服务',
        success(res) {
          if (res.confirm) {
            setTimeout(function () {
              wx.switchTab({
                url: '/pages/member/index?redirect=' + encodeURIComponent('/pages/aiCard/index?user_id=' + that.data.user_id),
              });
            }, 500)
          } else if (res.cancel) {

          }
        }
      })
    }else if(opid == id){
      wx.showToast({
        title: '不可给自己留言',
      })
    }else{
      wx.navigateTo({
        url: '/pages/adviser/chat/chat?id=' + id,
      })
    }
  },

  // 置业顾问拨打电话
  phone_now: function (e) {
    let phone = e.currentTarget.dataset.phone
    wx.makePhoneCall({
      phoneNumber: phone
    })
  },

  poster() {
    const user_id = this.data.user_id;
    if (user_id) {
      wx.navigateTo({
        url: '/pages/member/aiCard/index?id=' + user_id,
      })
    }
  },

  zaixian() {
    let that = this;
    const user_id = this.data.user_id;
    app.core('get', 'newhouse/myZaixianList?user_id=' + user_id, '', (res => {
      that.setData({
        zaixian: res.data,
      })
    }))
  },

})
